﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using WebSiteAdminTool.UI.MembershipService;
using WebSiteAdminTool.UI.Utils;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using WebSiteAdminTool.UI.Utils.Commands;
using GalaSoft.MvvmLight.Messaging;
using WebSiteAdminTool.UI.ViewModels.Base;

namespace WebSiteAdminTool.UI.ViewModels.Security.Users
{
    public class EditUserViewModel : BaseDialogViewModel
    {
        #region private data

        private UserData _user = null;

        #endregion

        #region public props

        public UserData User
        {
            get { return _user; }
            set { _user = value; }
        }

        //public string Password
        //{
        //    get { return _password; }
        //    set
        //    {
        //        _password = value;
        //        RaisePropertyChanged("Password");
        //    }
        //}

        //public string ConfirmedPassword
        //{
        //    get { return _confirmedPassword; }
        //    set
        //    {
        //        _confirmedPassword = value;
        //        RaisePropertyChanged("ConfirmedPassword");
        //    }
        //}

        public override string DialogTitle
        {
            get { return "Edit User"; }
        }

        #endregion

        #region data methods

        protected override void DoSave()
        {
            if (null != this.User)
            {
                var client = new MembershipServiceClient();
                UpdateUser(client);
            }
        }

        private void UpdateUser(MembershipServiceClient client)
        {
            client.UpdateUserCompleted += new EventHandler<UpdateUserCompletedEventArgs>(client_UpdateUserCompleted);
            client.UpdateUserAsync(this.User);
        }

        void client_UpdateUserCompleted(object sender, UpdateUserCompletedEventArgs e)
        {
            SaveCompleted<UserData>(e, e.Result);
        }

        #endregion
    }
}
